package com.lh.glassmuseum.service;

import com.lh.glassmuseum.HelloApplication;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MediaService {
    private static final Logger LOGGER = LoggerFactory.getLogger(MediaService.class);
    public static MediaPlayer passPlayer;
    public static MediaPlayer stopPlayer;
    public static MediaPlayer errorPlayer;

    public static void loadPlayer(){
        try{
            passPlayer = new MediaPlayer(new Media("file:///C:/config/pass.mp3"));
            stopPlayer = new MediaPlayer(new Media("file:///C:/config/stop.mp3"));
            errorPlayer = new MediaPlayer(new Media("file:///C:/config/error.mp3"));
        }catch (Exception e){
            LOGGER.error("读取音频文件失败",e);
            //替换logo
            ImageService.setErrorImg();
            //修改提示语言
            TipService.updateDisplay("读取音频文件错误，请检查音频文件是否存在");
        }
    }

    public static void playPass(){
        passPlayer.stop();
        passPlayer.play();
    }

    public static void playStop(){
        stopPlayer.stop();
        stopPlayer.play();
    }

    public static void playError(){
        errorPlayer.stop();
        errorPlayer.play();
    }
}
